﻿
@{
    Layout = null;
}

<style>
    .ngdialog.ngdialog-theme-plain .ngdialog-content {
        width: 25% !important;
    }
</style>
<div ng-controller="CounponListController">
    <h3>优惠券管理</h3>

    <div class="panel panel-default" ng-class="{ 'whirl standard': isLoading}">
        <div class="panel-heading">
            <div class="form-inline ng-pristine ng-valid">
                <div class="form-group">
                        <button type="submit" class="btn btn-labeled btn-success" ng-click="$state.go('app.couponinfo')">
                            <span class="btn-label">
                                <em class="fa fa-plus"></em>
                            </span>新增
                        </button>
                    </div>
            </div>
        </div>
        <div class="panel-body">
            <div class="table-responsive">
                <table ng-table="tableParams" class="table table-striped table-bproducted table-hover">
                    <tbody>
                        <tr ng-repeat="item in $data">
                            <td data-title="'优惠券名称'" class="text-center">{{item.CouponName}}</td>
                            <td data-title="'面额'" class="text-center">{{item.Amount}}</td>
                            <td data-title="'使用需满金额'" class="text-center">{{item.Consumption}}</td>
                            <td data-title="'发放总量'" class="text-center">{{item.TotalNum}}</td>
                            <td data-title="'已发放数'" class="text-center">{{item.ReceiveNum}}</td>
                            <td data-title="'使用截至日期'" class="text-center">{{item.EndTime}}</td>
                            <td data-title="'操作'" nowrap="nowrap" class="text-center">
                                <button type="button" ng-click="detail(item.Id)" class="btn btn-sm btn-primary" title="查看明细">
                                    <em class="fa fa-eye"></em>
                                </button>
                                <button type="button" ng-click="edit(item.Id)" class="btn btn-sm btn-edit" title="编辑">
                                    <em class="fa fa-edit"></em>
                                </button>
                                <button type="button" ng-click="delCoupon(item.Id)" class="btn btn-sm btn-danger" title="删除">
                                    <em class="fa fa-trash-o"></em>
                                </button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
        </div>
    </div>
</div>
<script>
    App.controller('CounponListController', [
    '$scope', '$resource', '$state', '$route', '$http', 'ngTableParams', 'ngTableDataService', 'Notify', '$filter', 'ngDialog', "$stateParams", "$timeout", "toaster",
        function ($scope, $resource, $state, $route, $http, ngTableParams, ngTableDataService, Notify, $filter, ngDialog, $stateParams, $timeout, toaster) {
            'use strict';
            $scope.isLoading = true;
            //数据查询
            $scope.tableParams = new ngTableParams({
                page: 1,
                count: 10,
                sorting: {
                    Id: 'desc'     // 初始化排序
                }
            }, {
                getData: function ($defer, params) {
                    $scope.isLoading = true;
                    var requestParams = {
                        Skip: (params.page() - 1) * params.count(),
                        Take: params.count(),
                    };
                    $http.post('/Coupon/GetCounponList', ngTableDataService.getServerSideParams(params.orderBy().toString(), params, requestParams))
                        .success(function (data, status) {
                            params.total(data.count);
                            $defer.resolve(data.data);
                            $scope.isLoading = false;
                        });
                }
            });

            

            $scope.detail = function (id) {
                $state.go('app.coupondetail', { "id": id });
            }


            $scope.edit = function (id) {
                $state.go('app.couponinfo', { "id": id });
            }

            $scope.delCoupon = function (id) {


                layer.confirm('确定删除吗？', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    $http.post("/Coupon/DelCounpon", { id: id }).then(function (response) {
                        layer.closeAll('dialog');
                        if (response.data.isSuccess) {
                            $scope.tableParams.$params.page = 1;
                            $scope.isLoading = true;
                            $scope.tableParams.reload();
                            $scope.isLoading = false;
                        }
                        else {

                            layer.msg(response.data.msg);
                        }

                    });
                }, function () {

                });
            }




        }
    ]);
</script>
